package com.itany.netclass.tran.impl;


import com.itany.netclass.exception.ServiceException;
import com.itany.netclass.tran.TransactionManager;
import com.itany.netclass.util.MyBatisUtil;

/**
 * Author:sjy@itany.com
 * Date:2021/9/30 10:17
 * Version:1.0-SNAPSHOT
 */
public class TransactionManagerImpl implements TransactionManager {
    @Override
    public void begin() {
        MyBatisUtil.getSession();
    }

    @Override
    public void commit() throws ServiceException {
        try {
            MyBatisUtil.getSession().commit();
            MyBatisUtil.close();
        } catch (Exception e) {
            e.printStackTrace();
            throw new ServiceException("事务提交出错");
        }
    }

    @Override
    public void rollback() throws ServiceException {
        try {
            MyBatisUtil.getSession().rollback();
            MyBatisUtil.close();
        } catch (Exception e) {
            e.printStackTrace();
            throw new ServiceException("事务回滚出错");
        }
    }
}
